package com.example.security_demo;

import com.example.security_demo.dao.UserDao;
import com.example.security_demo.pojo.User;
import com.example.security_demo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Date;
import java.util.List;

/**
 * TODO
 *
 * @author zzh
 * @date 2022/5/14
 * @since 1.0
 */
@SpringBootTest
@Slf4j
public class UserDaoTestDemo {

    @Autowired
    private UserDao userDao;

    @Autowired
    private UserService userService;

    @Test
    void testQuery() {
        System.out.println("hello world");
        long startTime = System.currentTimeMillis();
        List<User> users = userDao.selectList(null);
        System.out.println(System.currentTimeMillis() - startTime);
        System.out.println(users);
        assert users.size() == 0;
    }

    @Test
    void insertUser() {

        User user = new User();
        user.setUserId(1L);
        user.setMobile("13569599648");
        user.setPassword("yejinfeng");
        user.setSalt("ye");
        user.setEnable(true);
        user.setCreateTime(new Date());
        user.setUpdateTime(new Date());

        int result = userDao.insert(user);
        assert result == 1;

    }

    @Test
    void testQueryByMobile() {

        User user = userService.getUserByMobile("111");
        log.info("user is {}", user);
        assert user == null;
    }
}
